package com.mediastory.spsserver.guideFile.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.mediastory.spsserver.guideFile.dao.GuideFileDao;
import com.mediastory.spsserver.guideFile.domain.GuideFile;

@Repository
public class GuideFileDaoImpl extends SqlSessionDaoSupport  implements GuideFileDao {

	public GuideFileDaoImpl() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public List<GuideFile> SelectList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<GuideFile> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("GuideFile.selectList", condition, rb);
		}else{
			result = getSqlSession().selectList("GuideFile.selectList", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCnt(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("GuideFile.selectListTotalCnt", condition);
		return result;
	}

	@Override
	public GuideFile select(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		GuideFile result = (GuideFile)(getSqlSession().selectOne("GuideFile.select", condition)); 
		return result;
	}

	@Override
	public GuideFile insert(GuideFile guideFile) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("GuideFile.insert", guideFile);
		return guideFile;
	}

	@Override
	public GuideFile update(GuideFile guideFile) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("GuideFile.update", guideFile);
		return guideFile;
	}

	@Override
	public int delete(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("GuideFile.delete", condition);
		return result;
	}	

}